/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
#ifndef _BITOPS_H_
#define _BITOPS_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <inttypes.h>

/**
 * Converts given number to string in binary form (11010...), using 32 bit value
 * @param[out] bits  Buffer for string. (make big enough, MAX needed 33bytes)
 * @param[in] v      Value to convert.
 * @param[in] num    Number of bits to convert from value. (counting from LSB)
 * @return           Pointer to buffer 'bits' Or NULL if error.
 */
char *printBits(char *bits, uint32_t v, int num);


/**
 * Converts given number to string in binary form (11010...), using 64 bit value
 * @param[out] bits  Buffer for string. (make big enough, MAX needed 33bytes)
 * @param[in] v      Value to convert.
 * @param[in] num    Number of bits to convert from value. (counting from LSB)
 * @return           Pointer to buffer 'bits' Or NULL if error.
 */
char *printBits64(char *bits, uint64_t v, int num);

/**
 * Function to convert given binary string to a integer.
 * Note, only '1' is interpreted as '1', any other value is interpreted
 * as '0'
 * @param[in] str    NULL terminated string of 1 & 0:s.
 * @return           Value converted. 0 on errors and on zero values. ;)
 */
int readBits(char *str);

#ifdef __cplusplus
}
#endif

#endif
